/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cassys.dataaccess.hibernate;

import cassys.dataaccess.PeerAssessmentDAO;
import cassys.datatransferobjects.PeerAssessmentDTO;
import cassys.datatransferobjects.PeerAssessmentEvaluationDTO;
import cassys.datatransferobjects.TeamDTO;
import cassys.exceptions.HibernateAccessLayerException;
import java.util.ArrayList;

import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
 *
 * @author Priyanka
 */
public class PeerAssessmentDAOImpl extends AbstractDao implements PeerAssessmentDAO {

    @Override
    public void insertPeerAssessment(PeerAssessmentDTO dto) {
        Logger.getLogger(getClass().getName()).log(Level.INFO, "Inserting peer assessment " + dto.getPeerAssessId() );
     try {
            super.saveOrUpdate(dto);
            /*
           List<PeerAssessmentEvaluationDTO> items = new ArrayList<PeerAssessmentEvaluationDTO>();
               items=   dto.getPaEvalutionList();
            for (int i =0; i< items.size(); i++) {
                insertPeerAssessmentEvalution(items.get(i));
            }
             * */
             
        
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString()); 
        }
    } 
     
     
    @Override
    public void insertPeerAssessmentEvalution(PeerAssessmentEvaluationDTO dto) {
        try {
            Logger.getLogger(getClass().getName()).log(Level.INFO, "Inserting peer assessment item " + dto.getPeerAssessEvalutionId()+" for Assessmentid "+dto.getPeerAssessId());
            super.saveOrUpdate(dto);
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
    }
     

    @Override
    public void updatePeerAssessment(PeerAssessmentDTO dto) {
        try {
            //Logger.getLogger(getClass().getName()).log(Level.INFO, "Inserting product" + prod.getProductId());
            super.saveOrUpdate(dto);
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
    }

    @Override
    public void deletePeerAssessment(PeerAssessmentDTO dto) {
       try {
            //Logger.getLogger(getClass().getName()).log(Level.INFO, "Deleting product" + prod.getProductId());
            super.delete(dto);
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
        }
    }

    @Override
    public PeerAssessmentDTO findPeerAssessment(String paId) {
       
        PeerAssessmentDTO module = null;
        try {
            module = (PeerAssessmentDTO) super.find(PeerAssessmentDTO.class, paId);
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
        }
        return module;
    }

    @Override
    public PeerAssessmentDTO findPeerAssessmentByModule(String moduleCode){
         PeerAssessmentDTO module = null;
        try {
            module = (PeerAssessmentDTO) super.findByParam(PeerAssessmentDTO.class, "moduleCode", moduleCode);
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
        }
        return module;
    }
   

    @Override
    public void updatePeerAssessmentEvalution(PeerAssessmentEvaluationDTO dto) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void deletePeerAssessmentEvalution(PeerAssessmentEvaluationDTO dto) {
         try {
            //Logger.getLogger(getClass().getName()).log(Level.INFO, "Deleting product" + prod.getProductId());
            super.delete(dto);
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
        }
    }

    @Override
    public PeerAssessmentEvaluationDTO findPeerAssessmentEvalution(String paEvalId) {
   
        PeerAssessmentEvaluationDTO module = null;
        try {
            module = (PeerAssessmentEvaluationDTO) super.find(PeerAssessmentEvaluationDTO.class, paEvalId);
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
        }
        return module;
    }

    @Override
    public PeerAssessmentEvaluationDTO[] findALLPeerAssessmentEvalution() {
      
           try {
            List ls = findAll(PeerAssessmentEvaluationDTO.class);
            PeerAssessmentEvaluationDTO[] list = new PeerAssessmentEvaluationDTO[ls.size()];
            ls.toArray(list);
            return list;
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
        
    }
    
    @Override
     public PeerAssessmentEvaluationDTO[] findPeerAssessmentEvalutionForAPA(String paID){
      try {
            List ls =findAllByParam(PeerAssessmentEvaluationDTO.class, "peerAssessId", paID);
            PeerAssessmentEvaluationDTO[] list = new PeerAssessmentEvaluationDTO[ls.size()];
            ls.toArray(list);
            return list;
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
     
     
     }

  
    
}

   
